package umacis.implementation;

import java.util.Enumeration;
import java.util.Vector;

import com.sun.lwuit.util.Log;

import sampleapps.Calculator;
import umacis.implementation.ActionHook;
import umacis.implementation.ActionIndexOutOfRangeException;
import umacis.implementation.ActionNotDefinedException;
import umacis.implementation.Actions;
import umacis.implementation.Handle;
import umacis.implementation.Hookable;




public class HookManager {	
	static HookManager ui = new HookManager();
	boolean isCollecting;
	private Vector vectorOfHandles = new Vector();
	
	public static HookManager getInstance() {
		return ui;
		
	}
	private class HookableClass {
		public String name;
		public Vector actionHooks;
		public Vector variableHooks;
		
		public HookableClass(String className) {
			this.name = className;
		}

		public boolean equals(Object object) {
			return ((HookableClass)object).name.equals(this.name);
			
		}
	}
	private Vector hookableClasses = new Vector();
	private HookableClass currentHookableClass;

	
	public void getHandles(Actions actions) {
		for (int i = 0; i < Actions.MAXNUMBEROF_actions; i++)	{
		
				try {
					vectorOfHandles.addElement(Handle.getHandle(actions, i));
				} catch (ActionIndexOutOfRangeException e1) {
					Log.p(e1.getMessage(),Log.DEBUG);
					e1.printStackTrace();
				} catch (ActionNotDefinedException e) {
					Log.p("This action is not defined: nr " +String.valueOf(i), Log.DEBUG);
		
				}
				
		}
	}
	
	public void getHooks(String className, Hookable hookable) {
		 
		int index = hookableClasses.indexOf(new HookableClass(className));
		if (index == -1) { 
			currentHookableClass = new HookableClass(className);
			hookableClasses.addElement(currentHookableClass);
		}
		else currentHookableClass = (HookableClass) hookableClasses.elementAt(index);
		currentHookableClass.actionHooks = new Vector();
		currentHookableClass.variableHooks = new Vector();
		hookable.declareHooks();
	}
	

	public void register(ActionHook actionHandle) {
		currentHookableClass.actionHooks.addElement(actionHandle);
	}

	public void register(H_int H_int) {
		currentHookableClass.variableHooks.addElement(H_int);
		
	}

	public void updateUserDisplay(H_int h_int) {
		//Umacis.log("from updateUserDisplay", h_int.data );
		
	}


	public boolean isCollecting(int i, String string) {
		if (isCollecting) {
			
			return true;
		}
		return isCollecting;
	}

}
